package ${packageName}.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${packageCoreName}.core.controller.BaseController;
import ${packageName}.entity.${entityName};
import ${packageCoreName}.core.result.ResultData;
import ${packageName}.service.I${entityName}Service;
import ${packageName}.vo.${entityName}Vo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
* @author Faye.Wang
* @version 1.0
* @date 2021/1/6 14:03
* @Description
*/
@RestController
@RequestMapping("/api/${httpUrl}")
public class ${entityName}Controller extends BaseController {

	@Autowired
	private I${entityName}Service i${entityName}Service;

	/**
	* 保存数据
	* @param record
	* @return
	*/
	@PostMapping("/insert")
	public ResultData insert${entityName}(@RequestBody ${entityName}Vo record){
		${entityName} entity = new ${entityName}();
		BeanUtils.copyProperties(record,entity);
		i${entityName}Service.insertEntity(entity);
		return super.resultSuccess();
	}
	/**
	* 修改数据
	* @param record
	* @return
	*/
	@PostMapping("/update")
	public ResultData update${entityName}(@RequestBody ${entityName}Vo record){
		${entityName} entity = new ${entityName}();
		BeanUtils.copyProperties(record,entity);
		i${entityName}Service.updateEntity(entity);
		return super.resultSuccess();
	}
	/**
	* 查询数据
	* @param record
	* @return
	*/
	@PostMapping("/getId")
	public ResultData get${entityName}ById(@RequestBody ${entityName}Vo record){
		return super.resultSuccess(i${entityName}Service.selectByPrimaryKey(record.getId()));
	}

	/**
	* 删除数据
	* @param record
	* @return
	*/
	@PostMapping("/delete")
	public ResultData delete${entityName}ById(@RequestBody ${entityName}Vo record){
		i${entityName}Service.deletePrimaryKey(record.getId());
		return super.resultSuccess();
	}

	/**
	* 分页查询数据
	* @param record
	* @return
	*/
	@PostMapping("/getPageQuery")
	public ResultData getPageQuery(@RequestBody ${entityName}Vo record){
		${entityName} entity = new ${entityName}();
		BeanUtils.copyProperties(record,entity);

		return super.resultSuccess(i${entityName}Service.selectEntityList(new Page<>(record.getPageNo(), record.getPageSize()),entity));
	}

}
